package com.abc.scholarship.common.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-07-04  15:54
 */
@Component
public class RedisUtil {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    public Boolean lock(String key){
        return stringRedisTemplate.opsForValue().setIfAbsent(key, "1");
    }

    public void unlock(String key) {
        stringRedisTemplate.delete(key);
    }
}
